package com.xyht.sca_s.student_manage_system.modules.goods.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.goods.entity.req.SmsGoodsStockAddReq;
import com.xyht.sca_s.student_manage_system.modules.goods.service.SmsGoodsStockService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 物品库存表(--迎新) 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-01-17
 */
@RestController
@SecretBody
@RequestMapping("/goods/stock")
public class SmsGoodsStockController {

    @Resource
    private SmsGoodsStockService goodsStockService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("添加物品分类库存")
    @PostMapping("/add")
    public ResponseResult addGoodsStock(HttpServletRequest request, @RequestBody SmsGoodsStockAddReq addReq){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return goodsStockService.addGoodsStock(userId,addReq);
    }

    @ApiOperation("减少库存")
    @PostMapping("/reduce")
    public ResponseResult reduceGoodsStock(@RequestBody SmsGoodsStockAddReq reduceReq,HttpServletRequest request){
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return goodsStockService.reduceGoodsStock(reduceReq,userId);
    }

    @ApiOperation("查看库存历史记录列表")
    @GetMapping("/historyList")
    public ResponseResult getGoodsStockHistoryList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "searchStr", required = false) String searchStr,
                                                      @RequestParam(value = "classificationId", required = false) String classificationId,
                                                      @RequestParam(value = "stockType", required = false) Integer stockType) {
        return goodsStockService.getGoodsStockHistoryList(pageNum,pageSize,searchStr,stockType, classificationId);
    }
}

